﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ArgusLight.Drawing;

namespace ArgusLight.Fractals2D.ComplexFractalColoring.RouteLengthBased
{
	public class UserColoring : Coloring
	{
		private static readonly ColorEnum standardColorOne = ColorEnum.Turquoise;
		private static readonly ColorEnum standardColorTwo = ColorEnum.Blue;

		/// <summary>
		/// Type: <see cref="UserColoringParameter"/>
		/// </summary>
		public override Fractals2D.ColoringParameter Parameter
		{
			get
			{
				return this._parameter;
			}
			set
			{
				if (value is UserColoringParameter)
					this._parameter = (UserColoringParameter)value;
			}
		}
		private UserColoringParameter _parameter;
		protected new UserColoringParameter parameter { get { return (UserColoringParameter)this.Parameter; } }

		public UserColoring()
			: base()
		{
			this._parameter = UserColoringParameter.Default;
			this._parameter.ColorOne = UserColoring.standardColorOne.ToColor();
			this._parameter.ColorTwo = UserColoring.standardColorTwo.ToColor();
		}

		public override Color GetColor(int x, int y)
		{
			base.GetColor(x, y);
			byte[] a = GetBytes_Sinus3(this.data.iterations[x, y], this.fractalParameter.Iterations, this.data.routeLength[x, y], this.parameter.Frequency, this.parameter.Translation, this.parameter.ColorOne, this.parameter.ColorTwo);
			return Color.FromArgb(255, a[0], a[1], a[2]);
		}

		#region GetColorBytes
		public static byte[] GetBytes_Sinus3(Int32 i, Int32 MaxI, Double RouteLength, Double Frequency, Double Translation, Color c1, Color c2)
		{
			if (i >= MaxI || i < 1)
				return new byte[] { 0, 0, 0 };
			byte[] a = new byte[3];

			int r = c2.R - c1.R;
			int g = c2.G - c1.G;
			int b = c2.B - c1.B;

			Translation *= 2 * Math.PI;

			double d = (System.Math.Sin(RouteLength * Frequency + Translation) + 1) / 2;

			a[0] = (byte)(c1.R + r * d);
			a[1] = (byte)(c1.G + g * d);
			a[2] = (byte)(c1.B + b * d);

			return a;
		}
		#endregion
	}
}
